using System.Collections.Generic;
using UnityEngine;
using System;
using Object = UnityEngine.Object;

namespace Framework
{
    public class PoolManager : MonoSingleton<PoolManager>
    {
        private readonly Dictionary<Object, IGameObjectPool> pools = new();

        private GameObjectPool<T> _GetPool<T>(T prefab, Transform root, bool reset, Action<T> onHandeled) where T : Object
        {
            if (!pools.TryGetValue(prefab, out var pool))
            {
                pools.Add(prefab, pool = new GameObjectPool<T>(prefab, root ?? transform, reset, onHandeled));
            }
            return pool as GameObjectPool<T>;
        }

        public static GameObjectPool<T> GetPool<T>(T prefab, Transform root=null, bool reset=true, Action<T> onHandeled=null) where T : Object
            => Instance._GetPool(prefab, root, reset, onHandeled);
    }
}